package org.dei.perla.rockfall.gui.queryforge.panels;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import org.dei.perla.rockfall.gui.queryforge.ReadableStatusPanel;

public class RunningStatus1Panel extends ReadableStatusPanel {

	private JCheckBox jCheckBox1;
	private JComboBox jComboBox2;
	private JComboBox jComboBox3;
	private JCheckBox jCheckBox4;
	private JCheckBox jCheckBox5;
	private JCheckBox jCheckBox6;
	
	public RunningStatus1Panel(String title) {
		super(title);
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = -5766346334063942329L;

	@Override
	public int getStatus() {
		int retvalue = 0;
		
		boolean check1 = this.jCheckBox1.isSelected();
		boolean check4 = this.jCheckBox4.isSelected();
		boolean check5 = this.jCheckBox5.isSelected();
		boolean check6 = this.jCheckBox6.isSelected();

		int combo2 = this.jComboBox2.getSelectedIndex();
		int combo3 = this.jComboBox3.getSelectedIndex();
		
		if(check1)
			retvalue |= 0x10;
		
		if(check4)
			retvalue |= 0x1;
		
		if(check5)
			retvalue |= 0x2;
		
		if(check6)
			retvalue |= 0x4;
		
		switch(combo2){
			case 1:{
				retvalue |= 0x0100;
				break;
			}
			case 2:{
				retvalue |= 0x0200;
				break;
			}
			case 3:{
				retvalue |= 0x0300;
				break;
			}
			default:{
				break;
			}
		}
		switch(combo3){
			case 1:{
				retvalue |= 0x1000;
				break;
			}
			case 2:{
				retvalue |= 0x2000;
				break;
			}
			default:{
				break;
			}
		}
		return retvalue;
	}
	
	public void setStatus(int stato) {
		this.jCheckBox1.setSelected((stato & 0x10) > 0);
		this.jCheckBox4.setSelected((stato & 0x1) > 0);
		this.jCheckBox5.setSelected((stato & 0x2) > 0);
		this.jCheckBox6.setSelected((stato & 0x4) > 0);
		this.jComboBox2.setSelectedIndex((stato/0x100)&0xF);
		this.jComboBox3.setSelectedIndex((stato/0x1000)&0xF);
	}

	@Override
	protected void setupInternalComponents() {
		
		//Primo blocco di scelte
		
		jCheckBox1 = new JCheckBox();
		JLabel jlabel1 = new JLabel("Abilita Filtri parametrici");
		JPanel jpanel1 = new JPanel();
		BoxLayout layout1 = new BoxLayout(jpanel1, BoxLayout.X_AXIS);
		jpanel1.add(jlabel1);
		jpanel1.add(jCheckBox1);
		
		//Secondo Blocco di scelte
		
		jComboBox2 = new JComboBox();
		jComboBox2.setEditable(false);
		jComboBox2.addItem("16 campioni");
		jComboBox2.addItem("32 campioni");
		jComboBox2.addItem("64 campioni");
		jComboBox2.addItem("128 campioni");
		jComboBox2.setSelectedIndex(3);
		
		JLabel jlabel2 = new JLabel("Maschera parametri STA");
		JPanel jpanel2 = new JPanel();
		BoxLayout layout2 = new BoxLayout(jpanel2, BoxLayout.X_AXIS);
		jpanel2.add(jlabel2);
		jpanel2.add(jComboBox2);
		
        //Terzo Blocco di scelte
		
		jComboBox3 = new JComboBox();
		jComboBox3.setEditable(false);
		jComboBox3.addItem("64 campioni");
		jComboBox3.addItem("128 campioni");
		jComboBox3.addItem("256 campioni");
		jComboBox3.setSelectedIndex(2);
		
		JLabel jlabel3 = new JLabel("Maschera parametri LTA");
		JPanel jpanel3 = new JPanel();
		BoxLayout layout3 = new BoxLayout(jpanel3, BoxLayout.X_AXIS);
		jpanel3.add(jlabel3);
		jpanel3.add(jComboBox3);
		
		//Quarto blocco di scelte
		
		jCheckBox4 = new JCheckBox();
		jCheckBox4.setSelected(true);
		JLabel jlabel4 = new JLabel("Abilita filtro media mobile sui canali mems static");
		JPanel jpanel4 = new JPanel();
		BoxLayout layout4 = new BoxLayout(jpanel4, BoxLayout.X_AXIS);
		jpanel4.add(jlabel4);
		jpanel4.add(jCheckBox4);

		//Quinto blocco di scelte
		
		jCheckBox5 = new JCheckBox();
		jCheckBox5.setSelected(true);
		JLabel jlabel5 = new JLabel("Abilita filtro media mobile sui canali mems crackmeter");
		JPanel jpanel5 = new JPanel();
		BoxLayout layout5 = new BoxLayout(jpanel5, BoxLayout.X_AXIS);
		jpanel5.add(jlabel5);
		jpanel5.add(jCheckBox5);
		
		//Quinto blocco di scelte
		
		jCheckBox6 = new JCheckBox();
		jCheckBox6.setSelected(true);
		JLabel jlabel6 = new JLabel("Abilita filtro media mobile sui canali mems thermal");
		JPanel jpanel6 = new JPanel();
		BoxLayout layout6 = new BoxLayout(jpanel6, BoxLayout.X_AXIS);
		jpanel6.add(jlabel6);
		jpanel6.add(jCheckBox6);
		
		//aggiungo tutti i blocchi
		this.add(jpanel1);
		this.add(jpanel2);
		this.add(jpanel3);
		this.add(jpanel4);
		this.add(jpanel5);
		this.add(jpanel6);
	}
	

}
